/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package irsystem.scenario.method;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 *
 * @author Cerulean
 */
public class DocumentRank
{

    public boolean containDocID(int get) {
        boolean con=false;
        for(RankEntry entry:documentRanks)
        {
            if(entry.docID==get)
            {
                con=true;
                break;
            }
        }
        return con;
    }
    
    public RankEntry getRankEntry(int docID)
    {
        for(RankEntry entry:documentRanks)
        {
            if(entry.docID==docID)
            {
                return entry;
            }
        }
        return null;
    }
    
    public static class RankEntry implements Comparable<RankEntry>
    {
        int docID;
        double similarity;

        public RankEntry(int docID, double similarity)
        {
            this.docID = docID;
            this.similarity = similarity;
        }

        public int getDocID()
        {
            return docID;
        }

        public double getSimilarity()
        {
            return similarity;
        }

        public void setSimilarity(double similarity) {
            this.similarity = similarity;
        }

        public int compareTo(RankEntry o)
        {
            if(getSimilarity()==o.getSimilarity())
            {
                return 0;
            }
            else if(getSimilarity()<o.getSimilarity())
            {
                return -1;
            }
            else
            {
                return 1;
            }
        }
    }
    
    List<RankEntry> documentRanks;

    public DocumentRank()
    {
        this.documentRanks = new ArrayList<RankEntry>();
    }
    
    public void sort()
    {
        Collections.sort(documentRanks);
        Collections.reverse(documentRanks);
    }
    
    public void addEntry(RankEntry entry)
    {
        documentRanks.add(entry);
    }

    public List<RankEntry> getDocumentRanks()
    {
        return documentRanks;
    }
    
    public RankEntry getEntry(int index)
    {
        return documentRanks.get(index);
    }
    
    public List<Integer> getDocIDs()
    {
        List<Integer> ids=new ArrayList<Integer>();
        for(RankEntry entry:documentRanks)
        {
            ids.add(entry.getDocID());
        }
        return ids;
    }
}
